using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.IO;
using System.IO.Ports;
using System.Threading;
using System.Threading.Tasks;
using System.Windows.Forms;
using Modbus.Device;
using VncSharp;

namespace 发电机组监测
{
	// Token: 0x02000002 RID: 2
	public class Form1 : Form
	{
		// Token: 0x06000001 RID: 1 RVA: 0x00002050 File Offset: 0x00000250
		public Form1()
		{
			this.InitializeComponent();

			// NOTE: if you want to add your own delegate for the password
			// handler, you do it here (see static GetPassword() function above).
			_rd.GetPassword = new AuthenticateDelegate(GetPassword);
		}

        private static string GetPassword()
        {
            // Do your database/file/etc. work here and return a password
            return "lenghun";
        }

        // Token: 0x06000003 RID: 3 RVA: 0x00002C44 File Offset: 0x00000E44
        private void button1_Click(object sender, EventArgs e)
		{
			bool flag = this.comboBox1.SelectedIndex >= 0;
			if (flag)
			{
				this.button1.Enabled = false;
				this.button2.Enabled = true;
				this.button3.Enabled = true;
				this.button4.Enabled = true;
				this.button5.Enabled = true;
				bool flag2 = this.comboBox1.SelectedIndex >= 0;
				if (flag2)
				{
					this.serialPort1.PortName = this.comboBox1.SelectedItem.ToString();
					bool flag3 = !this.serialPort1.IsOpen;
					if (flag3)
					{
						try
						{
							this.serialPort1.Open();
							this.master = ModbusSerialMaster.CreateRtu(this.serialPort1);
							this.master.Transport.ReadTimeout = 5000;
							this.master.Transport.WriteTimeout = 5000;
							bool @checked = this.checkBox2.Checked;
							if (@checked)
							{
								this.timer1.Enabled = true;
							}
							//this.Text = this.FormName + this.textBox1.Text + " 已打开";
						}
						catch
						{
						}
					}
				}
			}
		}

		// Token: 0x06000004 RID: 4 RVA: 0x00002DA0 File Offset: 0x00000FA0
		private void button2_Click(object sender, EventArgs e)
		{
			this.timer1.Enabled = false;
			bool isOpen = this.serialPort1.IsOpen;
			if (isOpen)
			{
				this.master.Dispose();
				this.serialPort1.Close();
				//this.Text = this.FormName + this.textBox1.Text + " 已关闭";
			}
			this.button2.Enabled = false;
			this.button1.Enabled = true;
			this.button3.Enabled = false;
			this.button4.Enabled = false;
			this.button5.Enabled = false;
		}

		// Token: 0x06000009 RID: 9 RVA: 0x00003240 File Offset: 0x00001440
		private void button3_Click(object sender, EventArgs e)
		{
			bool isOpen = this.serialPort1.IsOpen;
			if (isOpen)
			{
				ushort[] expr_17 = new ushort[3];
				expr_17[0] = 1;
				ushort[] reg = expr_17;
				try
				{
					this.master.WriteMultipleRegisters(1, 0, reg);
				}
				catch
				{
				}
			}
		}

		// Token: 0x06000008 RID: 8 RVA: 0x000031EC File Offset: 0x000013EC
		private void button4_Click(object sender, EventArgs e)
		{
			bool isOpen = this.serialPort1.IsOpen;
			if (isOpen)
			{
				ushort[] expr_17 = new ushort[3];
				expr_17[1] = 1;
				ushort[] reg = expr_17;
				try
				{
					this.master.WriteMultipleRegisters(1, 0, reg);
				}
				catch
				{
				}
			}
		}

		// Token: 0x0600000F RID: 15 RVA: 0x000034B0 File Offset: 0x000016B0
		private void button5_Click(object sender, EventArgs e)
		{
			bool isOpen = this.serialPort1.IsOpen;
			if (isOpen)
			{
				ushort[] reg = new ushort[]
				{
					0,
					0,
					1
				};
				try
				{
					this.master.WriteMultipleRegisters(1, 0, reg);
				}
				catch
				{
				}
			}
		}

		// Token: 0x0600000C RID: 12 RVA: 0x000032E8 File Offset: 0x000014E8
		private void checkBox1_CheckedChanged(object sender, EventArgs e)
		{
			bool @checked = this.checkBox1.Checked;
			if (@checked)
			{
				bool flag = !this.serialPort1.IsOpen;
				if (flag)
				{
					bool flag2 = this.comboBox1.SelectedIndex >= 0;
					if (flag2)
					{
						this.serialPort1.PortName = this.comboBox1.SelectedItem.ToString();
						try
						{
							this.serialPort1.Open();
							this.master = ModbusSerialMaster.CreateRtu(this.serialPort1);
							this.master.Transport.ReadTimeout = 5000;
							this.master.Transport.WriteTimeout = 5000;
							this.button1.Enabled = false;
							this.button2.Enabled = true;
							this.button3.Enabled = true;
							this.button4.Enabled = true;
							this.button5.Enabled = true;
							bool checked2 = this.checkBox2.Checked;
							if (checked2)
							{
								this.timer1.Enabled = true;
							}
						}
						catch
						{
						}
					}
				}
			}
		}

		// Token: 0x0600000D RID: 13 RVA: 0x00003418 File Offset: 0x00001618
		private void checkBox2_CheckedChanged(object sender, EventArgs e)
		{
			bool @checked = this.checkBox2.Checked;
			if (@checked)
			{
				bool isOpen = this.serialPort1.IsOpen;
				if (isOpen)
				{
					this.timer1.Enabled = true;
				}
			}
			else
			{
				this.timer1.Enabled = false;
			}
		}

		// Token: 0x06000010 RID: 16 RVA: 0x00003504 File Offset: 0x00001704
		protected override void Dispose(bool disposing)
		{
			bool flag = disposing && this.components != null;
			if (flag)
			{
				this.components.Dispose();
			}
			base.Dispose(disposing);
		}

		// Token: 0x06000007 RID: 7 RVA: 0x00003064 File Offset: 0x00001264
		private void Form1_FormClosed(object sender, FormClosedEventArgs e)
		{
			this.timer1.Enabled = false;
			bool isOpen = this.serialPort1.IsOpen;
			if (isOpen)
			{
				this.master.Dispose();
				this.serialPort1.Close();
			}
			Dictionary<string, string> iniData = new Dictionary<string, string>();
			bool flag = this.comboBox1.SelectedIndex >= 0;
			if (flag)
			{
				iniData["串口.串口号"] = this.comboBox1.SelectedItem.ToString();
			}
			else
			{
				iniData["串口.串口号"] = "COM1";
			}
			bool flag2 = this.textBox1.Text != "";
			if (flag2)
			{
				iniData["发电机.名称"] = this.textBox1.Text;
			}
			else
			{
				iniData["发电机.名称"] = "发电机1";
			}
			bool @checked = this.checkBox1.Checked;
			if (@checked)
			{
				iniData["串口.自动打开"] = "1";
			}
			else
			{
				iniData["串口.自动打开"] = "0";
			}
			bool checked2 = this.checkBox2.Checked;
			if (checked2)
			{
				iniData["巡检.自动打开"] = "1";
			}
			else
			{
				iniData["巡检.自动打开"] = "0";
			}
			iniData["窗体.左边距"] = this.FormLeft.ToString();
			iniData["窗体.上边距"] = this.FormTop.ToString();
			Form1.WriteIniFile(this.filePath, iniData);
		}

		// Token: 0x0600000E RID: 14 RVA: 0x00003464 File Offset: 0x00001664
		private void Form1_FormClosing(object sender, FormClosingEventArgs e)
		{
			bool taskBusy = Form1.TaskBusy;
			if (taskBusy)
			{
				e.Cancel = true;
			}
			else
			{
				this.FormLeft = base.Location.X;
				this.FormTop = base.Location.Y;
			}

            if (_rd.IsConnected)
                _rd.Disconnect();

            base.OnClosing(e);

        }


        // Token: 0x06000002 RID: 2 RVA: 0x000023A8 File Offset: 0x000005A8
        private void Form1_Load(object sender, EventArgs e)
		{
			string currentDirectory = AppDomain.CurrentDomain.BaseDirectory;
			string currentDirectory2 = currentDirectory.Substring(0, currentDirectory.Length - 1);
            string folderName = currentDirectory2.Substring(currentDirectory2.LastIndexOf('\\') + 1);
            mutexApp = new Mutex(initiallyOwned: false, folderName, out var blnIsRunning);
            if (!blnIsRunning)
			{
				MessageBox.Show("程序已经运行！", "提示", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
				Environment.Exit(0);
			}
			else
			{
				//this.Text = this.FormName;
				this.filePath = currentDirectory + "config.ini";
				string[] ports = SerialPort.GetPortNames();
				ComboBox.ObjectCollection arg_9C_0 = this.comboBox1.Items;
				object[] items = ports;
				arg_9C_0.AddRange(items);
				Dictionary<string, string> iniData = Form1.ReadIniFile(this.filePath);
				string Left;
				bool flag2 = iniData.TryGetValue("窗体.左边距", out Left);
				if (flag2)
				{
					bool flag3 = Left != "";
					if (flag3)
					{
						this.FormLeft = Convert.ToInt32(Left);
					}
				}
				string Top;
				bool flag4 = iniData.TryGetValue("窗体.上边距", out Top);
				if (flag4)
				{
					bool flag5 = Top != "";
					if (flag5)
					{
						this.FormTop = Convert.ToInt32(Top);
					}
				}
				bool flag6 = this.FormLeft >= 0 && this.FormTop >= 0;
				if (flag6)
				{
					base.Location = new Point(this.FormLeft, this.FormTop);
				}
				string Name;
				bool flag7 = iniData.TryGetValue("发电机.名称", out Name);
				if (flag7)
				{
					bool flag8 = Name != "";
					if (flag8)
					{
						this.textBox1.Text = Name;
						//this.Text = this.FormName + this.textBox1.Text + " 已关闭";
					}
				}
				string AutoOpen;
				bool flag9 = iniData.TryGetValue("串口.自动打开", out AutoOpen);
				if (flag9)
				{
					bool flag10 = AutoOpen == "1";
					if (flag10)
					{
						this.checkBox1.Checked = true;
					}
				}
				string AutoScan;
				bool flag11 = iniData.TryGetValue("巡检.自动打开", out AutoScan);
				if (flag11)
				{
					bool flag12 = AutoScan == "1";
					if (flag12)
					{
						this.checkBox2.Checked = true;
					}
				}
				string comx;
				bool flag13 = iniData.TryGetValue("串口.串口号", out comx);
				if (flag13)
				{
					bool flag14 = comx != "";
					if (flag14)
					{
						int index = this.comboBox1.FindStringExact(comx);
						bool flag15 = index >= 0;
						if (flag15)
						{
							this.comboBox1.SelectedIndex = index;
							bool @checked = this.checkBox1.Checked;
							if (@checked)
							{
								this.serialPort1.PortName = comx;
								bool flag16 = !this.serialPort1.IsOpen;
								if (flag16)
								{
									try
									{
										this.serialPort1.Open();
										this.master = ModbusSerialMaster.CreateRtu(this.serialPort1);
										this.master.Transport.ReadTimeout = 5000;
										this.master.Transport.WriteTimeout = 5000;
										this.button1.Enabled = false;
										this.button2.Enabled = true;
										this.button3.Enabled = true;
										this.button4.Enabled = true;
										this.button5.Enabled = true;
										bool checked2 = this.checkBox2.Checked;
										if (checked2)
										{
											this.timer1.Enabled = true;
										}
										//this.Text = this.FormName + this.textBox1.Text + " 已打开";
									}
									catch
									{
									}
								}
							}
						}
					}
				}
				ListViewItem[] item = new ListViewItem[15];
				for (int i = 0; i < item.Length; i++)
				{
					item[i] = new ListViewItem();
				}
				item[0].Text = "1";
				item[0].SubItems.Add("蓄电池电压");
				item[0].SubItems.Add("0.0");
				item[0].SubItems.Add("V");
				item[1].Text = "2";
				item[1].SubItems.Add("发动机水温");
				item[1].SubItems.Add("0");
				item[1].SubItems.Add("℃");
				item[2].Text = "3";
				item[2].SubItems.Add("发动机转速");
				item[2].SubItems.Add("0");
				item[2].SubItems.Add("r/min");
				item[3].Text = "4";
				item[3].SubItems.Add("发动机机油压力");
				item[3].SubItems.Add("0.0");
				item[3].SubItems.Add("bar");
				item[4].Text = "5";
				item[4].SubItems.Add("发动机燃油位");
				item[4].SubItems.Add("0");
				item[4].SubItems.Add("%");
				item[5].Text = "6";
				item[5].SubItems.Add("发电频率");
				item[5].SubItems.Add("0.0");
				item[5].SubItems.Add("HZ");
				item[6].Text = "7";
				item[6].SubItems.Add("发电电压U相");
				item[6].SubItems.Add("0");
				item[6].SubItems.Add("V");
				item[7].Text = "8";
				item[7].SubItems.Add("发电电压V相");
				item[7].SubItems.Add("0");
				item[7].SubItems.Add("V");
				item[8].Text = "9";
				item[8].SubItems.Add("发电电压W相");
				item[8].SubItems.Add("0");
				item[8].SubItems.Add("V");
				item[9].Text = "10";
				item[9].SubItems.Add("发电电压UV");
				item[9].SubItems.Add("0");
				item[9].SubItems.Add("V");
				item[10].Text = "11";
				item[10].SubItems.Add("发电电压VW");
				item[10].SubItems.Add("0");
				item[10].SubItems.Add("V");
				item[11].Text = "12";
				item[11].SubItems.Add("发电电压WU");
				item[11].SubItems.Add("0");
				item[11].SubItems.Add("V");
				item[12].Text = "13";
				item[12].SubItems.Add("输出电流U相");
				item[12].SubItems.Add("0");
				item[12].SubItems.Add("A");
				item[13].Text = "14";
				item[13].SubItems.Add("输出电流V相");
				item[13].SubItems.Add("0");
				item[13].SubItems.Add("A");
				item[14].Text = "15";
				item[14].SubItems.Add("输出电流W相");
				item[14].SubItems.Add("0");
				item[14].SubItems.Add("A");
				this.listView1.BeginUpdate();
				ListViewItem[] array = item;
				for (int j = 0; j < array.Length; j++)
				{
					ListViewItem itemx = array[j];
					this.listView1.Items.Add(itemx);
				}
				this.listView1.EndUpdate();
			}
		}

		// Token: 0x06000011 RID: 17 RVA: 0x0000353C File Offset: 0x0000173C
		private void InitializeComponent()
		{
            this.components = new System.ComponentModel.Container();
            System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(Form1));
            this.button1 = new System.Windows.Forms.Button();
            this.comboBox1 = new System.Windows.Forms.ComboBox();
            this.label1 = new System.Windows.Forms.Label();
            this.tabControl1 = new System.Windows.Forms.TabControl();
            this.tabPage1 = new System.Windows.Forms.TabPage();
            this.label8 = new System.Windows.Forms.Label();
            this.label7 = new System.Windows.Forms.Label();
            this.label6 = new System.Windows.Forms.Label();
            this.label5 = new System.Windows.Forms.Label();
            this.button5 = new System.Windows.Forms.Button();
            this.listView1 = new System.Windows.Forms.ListView();
            this.序号 = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader()));
            this.名称 = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader()));
            this.值 = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader()));
            this.单位 = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader()));
            this.label4 = new System.Windows.Forms.Label();
            this.label2 = new System.Windows.Forms.Label();
            this.button4 = new System.Windows.Forms.Button();
            this.button3 = new System.Windows.Forms.Button();
            this.tabPage3 = new System.Windows.Forms.TabPage();
            this.button7 = new System.Windows.Forms.Button();
            this.button6 = new System.Windows.Forms.Button();
            this.textBox2 = new System.Windows.Forms.TextBox();
            this._rd = new VncSharp.RemoteDesktop();
            this.tabPage4 = new System.Windows.Forms.TabPage();
            this.webView2 = new Microsoft.Web.WebView2.WinForms.WebView2();
            this.tabPage2 = new System.Windows.Forms.TabPage();
            this.textBox1 = new System.Windows.Forms.TextBox();
            this.label3 = new System.Windows.Forms.Label();
            this.checkBox2 = new System.Windows.Forms.CheckBox();
            this.checkBox1 = new System.Windows.Forms.CheckBox();
            this.button2 = new System.Windows.Forms.Button();
            this.serialPort1 = new System.IO.Ports.SerialPort(this.components);
            this.timer1 = new System.Windows.Forms.Timer(this.components);
            this.tabControl1.SuspendLayout();
            this.tabPage1.SuspendLayout();
            this.tabPage3.SuspendLayout();
            this.tabPage4.SuspendLayout();
            ((System.ComponentModel.ISupportInitialize)(this.webView2)).BeginInit();
            this.tabPage2.SuspendLayout();
            this.SuspendLayout();
            // 
            // button1
            // 
            this.button1.Location = new System.Drawing.Point(280, 53);
            this.button1.Name = "button1";
            this.button1.Size = new System.Drawing.Size(68, 20);
            this.button1.TabIndex = 0;
            this.button1.Text = "打开";
            this.button1.UseVisualStyleBackColor = true;
            this.button1.Click += new System.EventHandler(this.button1_Click);
            // 
            // comboBox1
            // 
            this.comboBox1.FormattingEnabled = true;
            this.comboBox1.Location = new System.Drawing.Point(189, 53);
            this.comboBox1.Name = "comboBox1";
            this.comboBox1.Size = new System.Drawing.Size(85, 20);
            this.comboBox1.TabIndex = 1;
            // 
            // label1
            // 
            this.label1.AutoSize = true;
            this.label1.Location = new System.Drawing.Point(130, 57);
            this.label1.Name = "label1";
            this.label1.Size = new System.Drawing.Size(53, 12);
            this.label1.TabIndex = 2;
            this.label1.Text = "串口列表";
            // 
            // tabControl1
            // 
            this.tabControl1.Controls.Add(this.tabPage1);
            this.tabControl1.Controls.Add(this.tabPage3);
            this.tabControl1.Controls.Add(this.tabPage4);
            this.tabControl1.Controls.Add(this.tabPage2);
            this.tabControl1.Dock = System.Windows.Forms.DockStyle.Fill;
            this.tabControl1.ItemSize = new System.Drawing.Size(72, 38);
            this.tabControl1.Location = new System.Drawing.Point(0, 0);
            this.tabControl1.Name = "tabControl1";
            this.tabControl1.SelectedIndex = 0;
            this.tabControl1.Size = new System.Drawing.Size(1564, 749);
            this.tabControl1.TabIndex = 3;
            this.tabControl1.Selected += new System.Windows.Forms.TabControlEventHandler(this.tabControl1_Selected);
            // 
            // tabPage1
            // 
            this.tabPage1.BackgroundImage = global::Properties.Resources.背景图_1;
            this.tabPage1.Controls.Add(this.label8);
            this.tabPage1.Controls.Add(this.label7);
            this.tabPage1.Controls.Add(this.label6);
            this.tabPage1.Controls.Add(this.label5);
            this.tabPage1.Controls.Add(this.button5);
            this.tabPage1.Controls.Add(this.listView1);
            this.tabPage1.Controls.Add(this.label4);
            this.tabPage1.Controls.Add(this.label2);
            this.tabPage1.Controls.Add(this.button4);
            this.tabPage1.Controls.Add(this.button3);
            this.tabPage1.Location = new System.Drawing.Point(4, 42);
            this.tabPage1.Name = "tabPage1";
            this.tabPage1.Padding = new System.Windows.Forms.Padding(3);
            this.tabPage1.Size = new System.Drawing.Size(1556, 703);
            this.tabPage1.TabIndex = 0;
            this.tabPage1.Text = "柴油机监控";
            this.tabPage1.UseVisualStyleBackColor = true;
            // 
            // label8
            // 
            this.label8.AutoSize = true;
            this.label8.Location = new System.Drawing.Point(401, 293);
            this.label8.Name = "label8";
            this.label8.Size = new System.Drawing.Size(17, 12);
            this.label8.TabIndex = 8;
            this.label8.Text = "0s";
            // 
            // label7
            // 
            this.label7.AutoSize = true;
            this.label7.Location = new System.Drawing.Point(401, 316);
            this.label7.Name = "label7";
            this.label7.Size = new System.Drawing.Size(0, 12);
            this.label7.TabIndex = 7;
            // 
            // label6
            // 
            this.label6.AutoSize = true;
            this.label6.Location = new System.Drawing.Point(131, 316);
            this.label6.Name = "label6";
            this.label6.Size = new System.Drawing.Size(0, 12);
            this.label6.TabIndex = 6;
            // 
            // label5
            // 
            this.label5.AutoSize = true;
            this.label5.Location = new System.Drawing.Point(130, 293);
            this.label5.Name = "label5";
            this.label5.Size = new System.Drawing.Size(0, 12);
            this.label5.TabIndex = 5;
            // 
            // button5
            // 
            this.button5.Enabled = false;
            this.button5.Location = new System.Drawing.Point(401, 341);
            this.button5.Name = "button5";
            this.button5.Size = new System.Drawing.Size(113, 44);
            this.button5.TabIndex = 4;
            this.button5.Text = "自动";
            this.button5.UseVisualStyleBackColor = true;
            this.button5.Click += new System.EventHandler(this.button5_Click);
            // 
            // listView1
            // 
            this.listView1.Columns.AddRange(new System.Windows.Forms.ColumnHeader[] {
            this.序号,
            this.名称,
            this.值,
            this.单位});
            this.listView1.FullRowSelect = true;
            this.listView1.GridLines = true;
            this.listView1.HideSelection = false;
            this.listView1.Location = new System.Drawing.Point(34, 14);
            this.listView1.Name = "listView1";
            this.listView1.Size = new System.Drawing.Size(524, 267);
            this.listView1.TabIndex = 3;
            this.listView1.UseCompatibleStateImageBehavior = false;
            this.listView1.View = System.Windows.Forms.View.Details;
            // 
            // 序号
            // 
            this.序号.Text = "序号";
            this.序号.Width = 44;
            // 
            // 名称
            // 
            this.名称.Text = "名称";
            this.名称.Width = 151;
            // 
            // 值
            // 
            this.值.Text = "值";
            this.值.Width = 128;
            // 
            // 单位
            // 
            this.单位.Text = "单位";
            this.单位.Width = 56;
            // 
            // label4
            // 
            this.label4.AutoSize = true;
            this.label4.Location = new System.Drawing.Point(48, 316);
            this.label4.Name = "label4";
            this.label4.Size = new System.Drawing.Size(77, 12);
            this.label4.TabIndex = 2;
            this.label4.Text = "故障警告信息";
            // 
            // label2
            // 
            this.label2.AutoSize = true;
            this.label2.Location = new System.Drawing.Point(48, 293);
            this.label2.Name = "label2";
            this.label2.Size = new System.Drawing.Size(65, 12);
            this.label2.TabIndex = 1;
            this.label2.Text = "控制器状态";
            // 
            // button4
            // 
            this.button4.Enabled = false;
            this.button4.Location = new System.Drawing.Point(238, 341);
            this.button4.Name = "button4";
            this.button4.Size = new System.Drawing.Size(113, 44);
            this.button4.TabIndex = 0;
            this.button4.Text = "启动";
            this.button4.UseVisualStyleBackColor = true;
            this.button4.Click += new System.EventHandler(this.button4_Click);
            // 
            // button3
            // 
            this.button3.Enabled = false;
            this.button3.Location = new System.Drawing.Point(80, 341);
            this.button3.Name = "button3";
            this.button3.Size = new System.Drawing.Size(113, 44);
            this.button3.TabIndex = 0;
            this.button3.Text = "停止";
            this.button3.UseVisualStyleBackColor = true;
            this.button3.Click += new System.EventHandler(this.button3_Click);
            // 
            // tabPage3
            // 
            this.tabPage3.BackgroundImage = global::Properties.Resources.背景图_1;
            this.tabPage3.Controls.Add(this.button7);
            this.tabPage3.Controls.Add(this.button6);
            this.tabPage3.Controls.Add(this.textBox2);
            this.tabPage3.Controls.Add(this._rd);
            this.tabPage3.Location = new System.Drawing.Point(4, 42);
            this.tabPage3.Name = "tabPage3";
            this.tabPage3.Padding = new System.Windows.Forms.Padding(3);
            this.tabPage3.Size = new System.Drawing.Size(1556, 765);
            this.tabPage3.TabIndex = 2;
            this.tabPage3.Text = "电池柜管理";
            this.tabPage3.UseVisualStyleBackColor = true;
            // 
            // button7
            // 
            this.button7.BackColor = System.Drawing.Color.Gold;
            this.button7.FlatStyle = System.Windows.Forms.FlatStyle.Flat;
            this.button7.Location = new System.Drawing.Point(82, 660);
            this.button7.Name = "button7";
            this.button7.Size = new System.Drawing.Size(226, 55);
            this.button7.TabIndex = 3;
            this.button7.Text = "放电按钮";
            this.button7.UseVisualStyleBackColor = false;
            // 
            // button6
            // 
            this.button6.BackColor = System.Drawing.Color.Green;
            this.button6.FlatStyle = System.Windows.Forms.FlatStyle.Flat;
            this.button6.Location = new System.Drawing.Point(82, 572);
            this.button6.Name = "button6";
            this.button6.Size = new System.Drawing.Size(226, 52);
            this.button6.TabIndex = 2;
            this.button6.Text = "充电按钮";
            this.button6.UseVisualStyleBackColor = false;
            // 
            // textBox2
            // 
            this.textBox2.BackColor = System.Drawing.SystemColors.Control;
            this.textBox2.Font = new System.Drawing.Font("微软雅黑", 12F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
            this.textBox2.Location = new System.Drawing.Point(15, 22);
            this.textBox2.Multiline = true;
            this.textBox2.Name = "textBox2";
            this.textBox2.Size = new System.Drawing.Size(367, 478);
            this.textBox2.TabIndex = 1;
            this.textBox2.Text = "充电方法：\r\n1、右侧管理页面中将电池柜切换成离网模式\r\n2、插上充电枪外部送电\r\n3、按下方充电按钮打开充电开关\r\n4、右侧管理页面中将电池柜切换成并网模式\r\n" +
    "5、右侧管理页面将就地手动设置充电功率20KW\r\n\r\n\r\n放电方法：\r\n1、关闭外部电源，拔掉充电枪\r\n2、右边管理页面中将电池柜设为离网\r\n3、右边管理页面中" +
    "启动电池柜\r\n4、点击下方放电按钮打开放电";
            // 
            // _rd
            // 
            this._rd.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) 
            | System.Windows.Forms.AnchorStyles.Left) 
            | System.Windows.Forms.AnchorStyles.Right)));
            this._rd.AutoScroll = true;
            this._rd.AutoScrollMinSize = new System.Drawing.Size(608, 427);
            this._rd.BackColor = System.Drawing.Color.MintCream;
            this._rd.Location = new System.Drawing.Point(393, 3);
            this._rd.Name = "_rd";
            this._rd.Size = new System.Drawing.Size(1160, 759);
            this._rd.TabIndex = 0;
            this._rd.ConnectComplete += new VncSharp.ConnectCompleteHandler(this._rd_ConnectComplete);
            this._rd.ConnectionLost += new System.EventHandler(this._rd_ConnectionLost);
            // 
            // tabPage4
            // 
            this.tabPage4.BackgroundImage = global::Properties.Resources.背景图_1;
            this.tabPage4.Controls.Add(this.webView2);
            this.tabPage4.Location = new System.Drawing.Point(4, 42);
            this.tabPage4.Name = "tabPage4";
            this.tabPage4.Padding = new System.Windows.Forms.Padding(3);
            this.tabPage4.Size = new System.Drawing.Size(1556, 765);
            this.tabPage4.TabIndex = 3;
            this.tabPage4.Text = "能耗统计";
            this.tabPage4.UseVisualStyleBackColor = true;
            // 
            // webView2
            // 
            this.webView2.AllowExternalDrop = true;
            this.webView2.CreationProperties = null;
            this.webView2.DefaultBackgroundColor = System.Drawing.Color.White;
            this.webView2.Dock = System.Windows.Forms.DockStyle.Fill;
            this.webView2.Location = new System.Drawing.Point(3, 3);
            this.webView2.Name = "webView2";
            this.webView2.Size = new System.Drawing.Size(1550, 759);
            this.webView2.TabIndex = 0;
            this.webView2.ZoomFactor = 1D;
            this.webView2.NavigationCompleted += new System.EventHandler<Microsoft.Web.WebView2.Core.CoreWebView2NavigationCompletedEventArgs>(this.webView2_NavigationCompleted);
            this.webView2.WebMessageReceived += new System.EventHandler<Microsoft.Web.WebView2.Core.CoreWebView2WebMessageReceivedEventArgs>(this.webView2_WebMessageReceived);
            // 
            // tabPage2
            // 
            this.tabPage2.BackgroundImage = global::Properties.Resources.背景图_1;
            this.tabPage2.Controls.Add(this.textBox1);
            this.tabPage2.Controls.Add(this.label3);
            this.tabPage2.Controls.Add(this.checkBox2);
            this.tabPage2.Controls.Add(this.checkBox1);
            this.tabPage2.Controls.Add(this.button2);
            this.tabPage2.Controls.Add(this.button1);
            this.tabPage2.Controls.Add(this.label1);
            this.tabPage2.Controls.Add(this.comboBox1);
            this.tabPage2.Location = new System.Drawing.Point(4, 42);
            this.tabPage2.Name = "tabPage2";
            this.tabPage2.Padding = new System.Windows.Forms.Padding(3);
            this.tabPage2.Size = new System.Drawing.Size(1556, 765);
            this.tabPage2.TabIndex = 1;
            this.tabPage2.Text = "端口配置";
            this.tabPage2.UseVisualStyleBackColor = true;
            // 
            // textBox1
            // 
            this.textBox1.Location = new System.Drawing.Point(201, 89);
            this.textBox1.Name = "textBox1";
            this.textBox1.Size = new System.Drawing.Size(73, 21);
            this.textBox1.TabIndex = 7;
            // 
            // label3
            // 
            this.label3.AutoSize = true;
            this.label3.Location = new System.Drawing.Point(130, 94);
            this.label3.Name = "label3";
            this.label3.Size = new System.Drawing.Size(65, 12);
            this.label3.TabIndex = 6;
            this.label3.Text = "发电机名称";
            // 
            // checkBox2
            // 
            this.checkBox2.AutoSize = true;
            this.checkBox2.Location = new System.Drawing.Point(276, 174);
            this.checkBox2.Name = "checkBox2";
            this.checkBox2.Size = new System.Drawing.Size(72, 16);
            this.checkBox2.TabIndex = 5;
            this.checkBox2.Text = "自动读取";
            this.checkBox2.UseVisualStyleBackColor = true;
            this.checkBox2.CheckedChanged += new System.EventHandler(this.checkBox2_CheckedChanged);
            // 
            // checkBox1
            // 
            this.checkBox1.AutoSize = true;
            this.checkBox1.Location = new System.Drawing.Point(147, 174);
            this.checkBox1.Name = "checkBox1";
            this.checkBox1.Size = new System.Drawing.Size(72, 16);
            this.checkBox1.TabIndex = 4;
            this.checkBox1.Text = "自动打开";
            this.checkBox1.UseVisualStyleBackColor = true;
            this.checkBox1.CheckedChanged += new System.EventHandler(this.checkBox1_CheckedChanged);
            // 
            // button2
            // 
            this.button2.Enabled = false;
            this.button2.Location = new System.Drawing.Point(354, 53);
            this.button2.Name = "button2";
            this.button2.Size = new System.Drawing.Size(68, 20);
            this.button2.TabIndex = 3;
            this.button2.Text = "关闭";
            this.button2.UseVisualStyleBackColor = true;
            this.button2.Click += new System.EventHandler(this.button2_Click);
            // 
            // timer1
            // 
            this.timer1.Interval = 250;
            this.timer1.Tick += new System.EventHandler(this.timer1_Tick);
            // 
            // Form1
            // 
            this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F);
            this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
            this.ClientSize = new System.Drawing.Size(1564, 749);
            this.Controls.Add(this.tabControl1);
            this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedSingle;
            this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon")));
            this.Name = "Form1";
            this.Text = "能源管理面板";
            this.FormClosing += new System.Windows.Forms.FormClosingEventHandler(this.Form1_FormClosing);
            this.FormClosed += new System.Windows.Forms.FormClosedEventHandler(this.Form1_FormClosed);
            this.Load += new System.EventHandler(this.Form1_Load);
            this.tabControl1.ResumeLayout(false);
            this.tabPage1.ResumeLayout(false);
            this.tabPage1.PerformLayout();
            this.tabPage3.ResumeLayout(false);
            this.tabPage3.PerformLayout();
            this.tabPage4.ResumeLayout(false);
            ((System.ComponentModel.ISupportInitialize)(this.webView2)).EndInit();
            this.tabPage2.ResumeLayout(false);
            this.tabPage2.PerformLayout();
            this.ResumeLayout(false);

		}

		// Token: 0x06000005 RID: 5 RVA: 0x00002E48 File Offset: 0x00001048
		private static Dictionary<string, string> ReadIniFile(string filePath)
		{
			Dictionary<string, string> iniData = new Dictionary<string, string>();
			try
			{
				using (StreamReader reader = new StreamReader(filePath))
				{
					string currentSection = "";
					string line;
					while ((line = reader.ReadLine()) != null)
					{
						line = line.Trim();
						bool flag = line.StartsWith("[") && line.EndsWith("]");
						if (flag)
						{
							currentSection = line.Substring(1, line.Length - 2);
						}
						else
						{
							bool flag2 = !string.IsNullOrEmpty(line) && !line.StartsWith(";");
							if (flag2)
							{
								int equalsIndex = line.IndexOf('=');
								bool flag3 = equalsIndex > 0;
								if (flag3)
								{
									string key = line.Substring(0, equalsIndex).Trim();
									string value = line.Substring(equalsIndex + 1).Trim();
									string sectionKey = currentSection + "." + key;
									iniData[sectionKey] = value;
								}
							}
						}
					}
				}
			}
			catch
			{
			}
			return iniData;
		}

		// Token: 0x0600000B RID: 11 RVA: 0x000032C6 File Offset: 0x000014C6
		private void textBox1_TextChanged(object sender, EventArgs e)
		{
			this.Text = this.FormName + this.textBox1.Text;
		}

		// Token: 0x0600000A RID: 10 RVA: 0x00003294 File Offset: 0x00001494
		private void timer1_Tick(object sender, EventArgs e)
		{
			bool taskBusy = Form1.TaskBusy;
			if (!taskBusy)
			{
				Task task = new Task(delegate
				{
					Form1.TaskBusy = true;
					bool isOpen = this.serialPort1.IsOpen;
					if (isOpen)
					{
						try
						{
							ushort[] reg = this.master.ReadHoldingRegisters(1, 100, 72);
							MethodInvoker mi = delegate
							{
								this.listView1.Items[0].SubItems[2].Text = ((double)reg[18] / 10.0).ToString("0.0");
								this.listView1.Items[1].SubItems[2].Text = reg[19].ToString();
								this.listView1.Items[2].SubItems[2].Text = reg[20].ToString();
								this.listView1.Items[3].SubItems[2].Text = ((double)reg[21] / 10.0).ToString("0.0");
								this.listView1.Items[4].SubItems[2].Text = reg[22].ToString();
								this.listView1.Items[5].SubItems[2].Text = ((double)reg[9] / 10.0).ToString("0.0");
								this.listView1.Items[6].SubItems[2].Text = reg[0].ToString();
								this.listView1.Items[7].SubItems[2].Text = reg[1].ToString();
								this.listView1.Items[8].SubItems[2].Text = reg[2].ToString();
								this.listView1.Items[9].SubItems[2].Text = reg[3].ToString();
								this.listView1.Items[10].SubItems[2].Text = reg[4].ToString();
								this.listView1.Items[11].SubItems[2].Text = reg[5].ToString();
								this.listView1.Items[12].SubItems[2].Text = reg[6].ToString();
								this.listView1.Items[13].SubItems[2].Text = reg[7].ToString();
								this.listView1.Items[14].SubItems[2].Text = reg[8].ToString();
								this.label5.Text = this.State[(int)reg[27]];
								bool flag = reg[42] >= 200;
								if (flag)
								{
									this.label6.Text = this.FaultWarning[(int)(reg[42] - 200 + 40)];
								}
								else
								{
									bool flag2 = reg[42] >= 100;
									if (flag2)
									{
										this.label6.Text = this.FaultWarning[(int)(reg[42] - 100)];
									}
									else
									{
										this.label6.Text = "";
									}
								}
								this.label7.Text = "读取成功！";
								this.label8.Text = reg[28].ToString("0s");
							};
							base.BeginInvoke(mi);
						}
						catch
						{
							MethodInvoker mi2 = delegate
							{
								this.label7.Text = "读取失败！";
							};
							base.BeginInvoke(mi2);
						}
					}
					Form1.TaskBusy = false;
				});
				task.Start();
			}
		}

		// Token: 0x06000006 RID: 6 RVA: 0x00002F70 File Offset: 0x00001170
		private static void WriteIniFile(string filePath, Dictionary<string, string> iniData)
		{
			using (StreamWriter writer = new StreamWriter(filePath))
			{
				string currentSection = "";
				foreach (KeyValuePair<string, string> kvp in iniData)
				{
					string[] parts = kvp.Key.Split(new char[]
					{
						'.'
					});
					bool flag = parts.Length > 1;
					if (flag)
					{
						string section = parts[0];
						string key = parts[1];
						bool flag2 = section != currentSection;
						if (flag2)
						{
							writer.WriteLine("[" + section + "]");
							currentSection = section;
						}
						writer.WriteLine(key + " = " + kvp.Value);
					}
				}
			}
		}

		// Token: 0x0400000B RID: 11
		private Button button1;

		// Token: 0x04000016 RID: 22
		private Button button2;

		// Token: 0x04000012 RID: 18
		private Button button3;

		// Token: 0x04000011 RID: 17
		private Button button4;

		// Token: 0x0400001C RID: 28
		private Button button5;

		// Token: 0x04000015 RID: 21
		private CheckBox checkBox1;

		// Token: 0x04000014 RID: 20
		private CheckBox checkBox2;

		// Token: 0x0400000C RID: 12
		private ComboBox comboBox1;

		// Token: 0x0400000A RID: 10
		private IContainer components = null;

		// Token: 0x04000009 RID: 9
		private string[] FaultWarning = new string[]
		{
			"总故障",
			"故障发电低电压",
			"故障发电高电压",
			"故障发电低频率",
			"故障发电高频率",
			"故障超负荷",
			"故障过电流",
			"",
			"故障欠速",
			"故障超速",
			"故障低油压",
			"故障高温",
			"故障油压低开关输入",
			"故障高温开关输入",
			"故障外部停机输入",
			"故障盘车失败",
			"故障停机失败",
			"故障转速信号丢失",
			"故障传感器1低温",
			"故障传感器1高温",
			"故障传感器1低油压",
			"故障传感器1高油压",
			"故障传感器1低油位",
			"故障传感器1高油位",
			"故障传感器2低温",
			"故障传感器2高温",
			"故障传感器2低油压",
			"故障传感器2高油压",
			"",
			"",
			"故障紧急停机",
			"",
			"总市电故障",
			"故障市电低电压",
			"故障市电高电压",
			"故障市电低频率",
			"故障市电高频率",
			"",
			"",
			"",
			"总警告",
			"警告发电低电压",
			"警告发电高电压",
			"警告发电低频率",
			"警告发电高频率",
			"警告超负荷",
			"警告过电流",
			"警告欠速",
			"警告超速",
			"警告低油压",
			"警告高温",
			"警告电池低电压",
			"警告电池高电压",
			"警告充电低电压",
			"警告燃料低",
			"警告传感器1低温",
			"警告传感器1高温",
			"警告传感器1低油压",
			"警告传感器1高油压",
			"警告传感器1低油位",
			"警告传感器1高油位",
			"警告传感器2低温",
			"警告传感器2高温",
			"警告传感器2低油压",
			"警告传感器2高油压",
			"",
			""
		};

		// Token: 0x04000004 RID: 4
		private string filePath = "";

		// Token: 0x04000006 RID: 6
		private int FormLeft = 0;

		// Token: 0x04000005 RID: 5
		private string FormName = "发电机组监控软件V1.0 ";

		// Token: 0x04000007 RID: 7
		private int FormTop = 0;

		// Token: 0x0400000D RID: 13
		private Label label1;

		// Token: 0x04000010 RID: 16
		private Label label2;

		// Token: 0x04000018 RID: 24
		private Label label3;

		// Token: 0x0400001B RID: 27
		private Label label4;

		// Token: 0x04000023 RID: 35
		private Label label5;

		// Token: 0x04000022 RID: 34
		private Label label6;

		// Token: 0x04000024 RID: 36
		private Label label7;

		// Token: 0x04000025 RID: 37
		private Label label8;

		// Token: 0x0400001D RID: 29
		private ListView listView1;

		// Token: 0x04000002 RID: 2
		private ModbusSerialMaster master;

		// Token: 0x04000003 RID: 3
		private Mutex mutexApp;

		// Token: 0x04000019 RID: 25
		private SerialPort serialPort1;

		// Token: 0x04000008 RID: 8
		private string[] State = new string[]
		{
			"停机",
			"手动准备",
			"自动模式",
			"",
			"预热延时",
			"启动准备",
			"启动延时",
			"盘车",
			"盘车延时",
			"盘车间隔延时",
			"启动成功安全延时",
			"怠速延时",
			"机组运行安全延时",
			"发电供电判断",
			"机组运行",
			"机组冷却延时",
			"停机延时",
			"停机",
			"停机"
		};

		// Token: 0x0400000E RID: 14
		private TabControl tabControl1;

		// Token: 0x0400000F RID: 15
		private TabPage tabPage1;

		// Token: 0x04000013 RID: 19
		private TabPage tabPage2;

		// Token: 0x04000001 RID: 1
		private static bool TaskBusy;

		// Token: 0x04000017 RID: 23
		private TextBox textBox1;

		// Token: 0x0400001A RID: 26
		private System.Windows.Forms.Timer timer1;

		// Token: 0x04000020 RID: 32
		private ColumnHeader 值;

		// Token: 0x04000021 RID: 33
		private ColumnHeader 单位;

		// Token: 0x0400001F RID: 31
		private ColumnHeader 名称;
        private TabPage tabPage3;
        private VncSharp.RemoteDesktop _rd;
        private TabPage tabPage4;
        private Microsoft.Web.WebView2.WinForms.WebView2 webView2;
        private TextBox textBox2;
        private Button button7;
        private Button button6;

        // Token: 0x0400001E RID: 30
        private ColumnHeader 序号;

        private void tabControl1_Selected(object sender, TabControlEventArgs e)
        {
            //System.Text.StringBuilder messageBoxCS = new System.Text.StringBuilder();
            //messageBoxCS.AppendFormat("{0} = {1}", "TabPage", e.TabPage);
            //messageBoxCS.AppendLine();
            //messageBoxCS.AppendFormat("{0} = {1}", "TabPageIndex", e.TabPageIndex);
            //messageBoxCS.AppendLine();
            //messageBoxCS.AppendFormat("{0} = {1}", "Action", e.Action);
            //messageBoxCS.AppendLine();
            //MessageBox.Show(messageBoxCS.ToString(), "Selected Event");


			if (e.TabPage.Text == "电池柜管理")
			{
				try
				{
					_rd.Connect("192.168.0.180", 0, false, false);
				}
				catch (Exception ex)
				{
					MessageBox.Show(this, ex.Message, Text, MessageBoxButtons.OK, MessageBoxIcon.Error);
				}
			}
			else
			{
                if (_rd.IsConnected)
                    _rd.Disconnect();
            }

			if (e.TabPage.Text == "能耗统计")
			{
				webView2.Source = new Uri("https://saas.kgooer.com");
			}
			else
			{
				//webView2.Source = new Uri("");

            }



        }


        private void _rd_ConnectComplete(object sender, ConnectEventArgs e)
        {
            //ClientSize = new Size(e.DesktopWidth, e.DesktopHeight);
            //Text = e.DesktopName;

            _rd.Focus();
        }

        private void _rd_ConnectionLost(object sender, EventArgs e)
        {
            // Let the user know of the lost connection
            //MessageBox.Show(this,
            //                "Lost Connection to Host.",
            //                "Connection Lost",
            //                MessageBoxButtons.OK,
            //                MessageBoxIcon.Information);
            //FlipMenuOptions();
        }


        private void webView2_WebMessageReceived(object sender, Microsoft.Web.WebView2.Core.CoreWebView2WebMessageReceivedEventArgs e)
        {
            var data = e.WebMessageAsJson;
            webView2.CoreWebView2.PostWebMessageAsJson(data);
        }

        private async void webView2_NavigationCompleted(object sender, Microsoft.Web.WebView2.Core.CoreWebView2NavigationCompletedEventArgs e)
        {
            await webView2.CoreWebView2.ExecuteScriptAsync($"document.querySelector('#tehForm > div:nth-child(1) > input[type=text]').value = 'hwg215';");
            await webView2.CoreWebView2.ExecuteScriptAsync($"document.querySelector('#tehForm > div:nth-child(2) > input[type=password]').value = '215005';");
            Thread.Sleep(500);
            await webView2.CoreWebView2.ExecuteScriptAsync($"document.querySelector('#tehForm > div:nth-child(3) > button').click();");

        }
    }
}
